package com.company.zhishidian;

import com.company.zhishidian.xuliehua.Students;

import java.util.ArrayList;
import java.util.List;

/**
 * 泛型
 */
public class Fanxing {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        // 可以自动检查
        Pair<Students> p = new Pair<>(new Students("ww",1,'a'),new Students("ww",1,'a'));
        // 可以自动转换
        Students s = p.getB();
        // 多个泛型自动识别
        Fan<String,Integer,Student,Boolean> f = new Fan<>("aaa",2,new Student("ww"),true);
    }
}

// 单个泛型类
class Pair<T>{
    private T b;
    private T g;

    public Pair(T b, T g) {
        this.b = b;
        this.g = g;
    }

    public T getB() {
        return b;
    }

    public void setB(T b) {
        this.b = b;
    }

    public T getG() {
        return g;
    }

    public void setG(T g) {
        this.g = g;
    }

    @Override
    public String toString() {
        return "Pair{" +
                "b=" + b +
                ", g=" + g +
                '}';
    }
}
// 多个泛型自定义类
class Fan<A,B,C,D>{
    A a;
    B b;
    C c;
    D d;

    public Fan(A a, B b, C c, D d) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }
}